<template>
  <div class="comment-reply">
    <van-nav-bar :title="commentTitle">
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>

    <div class="scroll-wrap">
      <comment-item :comment="comment" />
      <van-cell title="全部回复" />
      <!-- 评论的回复列表 -->
      <comment-list :list="commentList" :source="comment.com_id" type="c" />
    </div>
    <!-- 评论 -->
    <div class="post-wrap">
      <van-button round class="post-btn" size="small" @click="isPostShow = true"
        >写评论</van-button
      >
    </div>
    <!-- 发布评论 -->
    <van-popup v-model="isPostShow" position="bottom">
      <comment-post :target="comment.com_id" @post-success="onPostSuccess" />
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import CommentList from './comment-list'
import CommentPost from './comment-post'
export default {
  name: 'CommentReply',
  components: {
    CommentItem,
    CommentList,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      isPostShow: false,
      commentList: [] // 评论的回复列表
    }
  },
  computed: {
    commentTitle() {
      return this.comment.reply_count > 0
        ? `${this.comment.reply_count} 条回复`
        : '暂无回复'
    }
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onPostSuccess(data) {
      // 更新数量
      this.comment.reply_count++
      // 关闭弹窗
      this.isPostShow = false
      // // 评论显示顶端
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
